package b.q;

import android.os.Bundle;
import androidx.savedstate.Recreator;
import androidx.savedstate.SavedStateRegistry$1;
import b.n.d;
import b.n.h;
import java.util.Map.Entry;
import java.util.Objects;

/* compiled from: SavedStateRegistryController */
public final class b {
    public final c a;
    public final a b = new a();

    public b(c cVar) {
        this.a = cVar;
    }

    public void a(Bundle bundle) {
        d a = this.a.a();
        if (((h) a).b == b.n.d.b.INITIALIZED) {
            a.a(new Recreator(this.a));
            a aVar = this.b;
            if (aVar.c) {
                throw new IllegalStateException("SavedStateRegistry was already restored.");
            }
            if (bundle != null) {
                aVar.b = bundle.getBundle("androidx.lifecycle.BundlableSavedStateRegistry.key");
            }
            a.a(new SavedStateRegistry$1(aVar));
            aVar.c = true;
            return;
        }
        throw new IllegalStateException("Restarter must be created only during owner's initialization stage");
    }

    public void b(Bundle bundle) {
        a aVar = this.b;
        Objects.requireNonNull(aVar);
        Bundle bundle2 = new Bundle();
        Bundle bundle3 = aVar.b;
        if (bundle3 != null) {
            bundle2.putAll(bundle3);
        }
        b.c.a.b.b.d c = aVar.a.c();
        while (c.hasNext()) {
            Entry entry = (Entry) c.next();
            bundle2.putBundle((String) entry.getKey(), ((b.q.a.b) entry.getValue()).a());
        }
        bundle.putBundle("androidx.lifecycle.BundlableSavedStateRegistry.key", bundle2);
    }
}
